package com.os.mq;

import com.os.data.DataStore;
import com.os.model.DataNodeInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * 监听数据节点心跳消息
 * @author 风亦未止
 * @date 2023/5/5 23:49
 */
@Log4j2
@Component
public class DataHeartBeatListener {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "api_queue"),
            exchange = @Exchange(name = "api_exchange",type = ExchangeTypes.TOPIC),
            key = {"api_server"}
    ))
    public void listenHeartBeat(@Payload DataNodeInfo dataNodeInfo){
        DataStore.dataNodeStore.put(dataNodeInfo.getHost(),dataNodeInfo);
    }
}
